using System.Linq;
using System.Windows.Media;
using Common;
using Common.Enum;
using Common.NotifyEvent;
using SExperiment;
using SExperiment.ExperimentResult;
using SProject.BasicInformation;
using SSettings;

namespace SWellPlate
{
    public class ChartData : NotifyPropertyChanged
    {
        private WellCell _WellCell;

        private SampleTargetItem _SampleTargetItem;

        private bool _IsVisible = true;

        private bool _HighLight;

        public WellCell WellCell
        {
            get
            {
                return _WellCell;
            }
            set
            {
                if (_WellCell != value)
                {
                    _WellCell = value;
                    OnPropertyChanged("WellCell");
                }
            }
        }

        public SampleTargetItem SampleTargetItem
        {
            get
            {
                return _SampleTargetItem;
            }
            set
            {
                if (_SampleTargetItem != value)
                {
                    _SampleTargetItem = value;
                    OnPropertyChanged("SampleTargetItem");
                }
            }
        }

        public bool IsVisible
        {
            get
            {
                return _IsVisible;
            }
            set
            {
                if (_IsVisible != value)
                {
                    _IsVisible = value;
                    OnPropertyChanged("IsVisible");
                }
            }
        }

        public bool HighLight
        {
            get
            {
                return _HighLight;
            }
            set
            {
                if (_HighLight != value)
                {
                    _HighLight = value;
                    OnPropertyChanged("HighLight");
                }
            }
        }

        public Color GetChartDataColor(EColorMode colorMode)
        {
            if (SampleTargetItem.HasCustomColor(colorMode))
            {
                return SampleTargetItem.GetCustomColor(colorMode);
            }
            switch (colorMode)
            {
                case EColorMode.Channel:
                    return ConfigSettings.GetInstance().ExperimentSetting.ColorSettings.GetChannelColor(SampleTargetItem.ChannelNo);
                case EColorMode.Type:
                    return Utility.GetSampleColor(SampleTargetItem.SampleType);
                case EColorMode.Row:
                    return Utility.GetRowColor(WellCell.RowIndex + 1);
                case EColorMode.Column:
                    return Utility.GetColumnColor(WellCell.ColumnIndex + 1);
                case EColorMode.Result:
                    if (SampleTargetItem.Result is HRMTargetResult)
                    {
                        return Utility.GetDrawingGenoTypeColor(((HRMTargetResult)SampleTargetItem.Result).GenoType);
                    }
                    if (WellCell.Well.Result is ADWellResult)
                    {
                        return Utility.GetDrawingADGenoTypeColor(((ADWellResult)WellCell.Well.Result).TypeNo);
                    }
                    break;
                case EColorMode.Target:
                    return WellCell.Well.Project.Target.Items.Where((TargetItem s) => s.Name == SampleTargetItem.TargetName).FirstOrDefault().Color;
            }
            return Colors.Black;
        }

        public ESeriesType GetChartDataLinePointStyle(EColorMode colorMode)
        {
            if (SampleTargetItem.HasCustomLinePointStyle(colorMode))
            {
                return SampleTargetItem.GetCustomLinePointStyle(colorMode);
            }
            return ESeriesType.None;
        }
    }
}
